/**----------------------------------------------------------*/
/** JS:  cmi_goods_list.js（商品管理--商品信息）           */
/**----------------------------------------------------------*/

var tipc = 'GOODS';
var innder = 'innerJump.adm';

var add = function(){
	var p = innder + "?spt=,"+menuId+"&st="+tipc;
	location.replace(p);
};

var modify = function() {
	try {
//		var record = datagridOneRow('dataPanel');
//		if(record == null) {
//			return;
//		}
//		var p = innder + "?spt="+record.uuid+"&st="+tipc;
		var p = innder + "?spt=1,"+menuId+"&st="+tipc;
		location.replace(p);
	} catch (e) {
		showJsException(e,_msg_fail);
	}
};

var remove = function() {
	try {
		var rows = $('#dataPanel').datagrid("getSelections");
		if(rows.length == 0) {
			MyUtils.waring(_empty_select);
			return;
		}
		var ids = new Array();
		var names = new Array();
		for(var i = 0; i < rows.length; i++) {
			ids.push(rows[i].uuid);
			names.push(rows[i].categroy);
		}
		var data = { data:"["+MyUtils.createQueryConditionBean("uuid","customer","uuid IN (" + ids.toString() + ")","0",null) +"]"
			    ,st:tipc
			    ,msg:names.toString()
		};
		$.messager.confirm(_msg_sys,_remove_confirm, function(r) {
			if (r) {
				MyUtils.openMask(_msg_process,$('#t2'));
				MyUtils.sendPost("impl_remove/backRemove.adm",data,function(rets){
					try{
						MyUtils.hiddenMask($('#t2'));
						var res = MyUtils.toJsonObject(rets);
						if(res.error == '0') {
							MyUtils.info(res.msg);
							$('#dataPanel').datagrid("clearSelections");
							$('#dataPanel').datagrid("reload");
						} else {
							MyUtils.error(res.msg);
						}
					} catch (e) {
						showJsException(e);
					}
				});
			}
		});
	} catch (e) {
		showJsException(e,_msg_fail);
	}
};

var dbclick = function(index,row) {
	$('#dataPanel').datagrid("clearSelections");
	$('#dataPanel').datagrid("selectRow",index);
	modify();
};

function initPanel(){
	try {
		var columns = [  {field : 'uuid',title : '编号',width : 100,align : 'center',formatter:function(value){return MyUtils.valueAlign(value,"left");},sortable:true}
						,{field : 'goodsName',title : '商品名称',width : 300,align : 'center',formatter:function(value){return MyUtils.valueAlign(value,"left");},sortable:true}
						,{field : 'goodsBill',title : '货号',width : 150,align : 'center',formatter:function(value){return MyUtils.valueAlign(value,"left");},sortable:true}
						,{field : 'salePrice',title : '价格',width : 100,align : 'center',sortable:true}
						,{field : 'goodsDm8',title : '上架',width : 60,align : 'center',formatter:function(value){
							return '<img alt="OK" src="'+(value =='0' ? noPic:okPic) +'" style="border: 0px;">';
						},sortable:true}
						,{field : 'goodsBetter',title : '精品',width : 60,align : 'center',formatter:function(value){
							return '<img alt="OK" src="'+(value =='0' ? noPic:okPic) +'" style="border: 0px;">';
						},sortable:true}
						,{field : 'goodsNew',title : '新品',width : 60,align : 'center',formatter:function(value){
							return '<img alt="OK" src="'+(value =='0' ? noPic:okPic) +'" style="border: 0px;">';
						},sortable:true}
						,{field : 'goodsHot',title : '热销',width : 60,align : 'center',formatter:function(value){
							return '<img alt="OK" src="'+(value =='0' ? noPic:okPic) +'" style="border: 0px;">';
						},sortable:true}
						,{field : 'goodsSort',title : '推荐排序',width : 100,align : 'center',sortable:true}
						,{field : 'goodsSum',title : '库存',width : 100,align : 'center',sortable:true}
					];
		var pam = {qr:"[]",st:tipc,sco:'',dc:Dmlx.sort.desc};
		MyUtils.createPaginPanelWithQueryparams('dataPanel',null,Dmlx._hFrozenColumns,columns,toolbars,dbclick, panel,null);
		$('#dataPanel').datagrid({
			url:"impl_search/commonsPaginSearch.ajax",
			queryParams:pam,
			pagination:true,
			fitColumns:true
		});
	} catch (e) {
		showJsException(e,_msg_fail);
	}
}
//TODO LOAD
$(function(){
	initPanel();
});
